package com.lee.dml;

import com.lee.entity.Product;
import com.lee.entity.repository.ProductRepository;
import lombok.val;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

import java.math.BigDecimal;
import java.util.Optional;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2022/3/15
 */
@SpringBootTest
public class DocumentOperation {
    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;
    @Autowired
    private ProductRepository productRepository;

    @Test
    public void add() {
        final Product product = Product.builder()
                .id(1001L)
                .category("日用品")
                .url("/1/2/3/4")
                .name("拜登")
                .price(BigDecimal.valueOf(100))
                .build();
        productRepository.save(product);
    }

    @Test
    public void modify() {
        final Product product = Product.builder()
                .id(1001L)
                .category("日用品")
                .url("/1/2/3/4")
                .name("特朗普")
                .price(BigDecimal.valueOf(100))
                .build();
        productRepository.save(product);
    }

    @Test
    public void query() {
        final Optional<Product> product = productRepository.findById(1001L);
        product.ifPresent(i->System.out.println(i.toString()));
    }

    @Test
    public void queryAll() {
        final val all = productRepository.findAll();
        all.forEach(i->System.out.println(i.toString()));
    }

}
